/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.actions.assessmentManagement;

import cassys.actions.core.BaseAction;
import cassys.domain.assessment.*;
import cassys.domain.classManagement.Module;
import cassys.ejb.clients.AssessmentManagementDelegate;
import cassys.ejb.clients.ModuleManagementDelegate;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author User
 */
public class CreateAssessment extends BaseAction {

    private String title;
    private String description;
    private int maxMark;
    private int maxMarkRange;
    private int minMarkRange;
    private List<AssessmentItem> assessmentItems;
    private List<Module> modules;
    private Module module;
    private double weightPercentage;
    private AssessmentManagementDelegate assessmentDelegate;
    private ModuleManagementDelegate moduleDelegate;

    public CreateAssessment() {
        assessmentDelegate = new AssessmentManagementDelegate();
        moduleDelegate = new ModuleManagementDelegate();
    }

    @Override
    public String execute() throws Exception {
        module = new Module();
        modules = moduleDelegate.getAllModules();
        assessmentItems = new ArrayList<AssessmentItem>();
        System.out.println("assessment management action started");
        return SUCCESS;
    }

    public String createNewAssessment() throws Exception {
        System.out.println("invoke create assessment action");
        System.out.println(this.maxMark);
        System.out.println(this.assessmentItems.size());
        assessmentDelegate.crateAssessment(getNewAssessment());
        // assessmentDelegate.crateAssessment(mapToAssessment());
        return SUCCESS;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getMaxMark() {
        return maxMark;
    }

    public void setMaxMark(int maxMark) {
        this.maxMark = maxMark;
    }

    public int getMaxMarkRange() {
        return maxMarkRange;
    }

    public void setMaxMarkRange(int maxMarkRange) {
        this.maxMarkRange = maxMarkRange;
    }

    public int getMinMarkRange() {
        return minMarkRange;
    }

    public void setMinMarkRange(int minMarkRange) {
        this.minMarkRange = minMarkRange;
    }

    public List<AssessmentItem> getAssessmentItems() {
        return assessmentItems;
    }

    public void setAssessmentItems(List<AssessmentItem> assessmentItems) {
        this.assessmentItems = assessmentItems;
    }

    public Module getModule() {
        return module;
    }

    public void setModule(Module module) {
        this.module = module;
    }

    public double getWeightPercentage() {
        return weightPercentage;
    }

    public void setWeightPercentage(double weightPercentage) {
        this.weightPercentage = weightPercentage;
    }

    /**
     * @return the modules
     */
    public List<Module> getModules() {
        return modules;
    }

    /**
     * @param modules the modules to set
     */
    public void setModules(List<Module> modules) {
        this.modules = modules;
    }

    private Assessment getNewAssessment() {
        Assessment newAssessment = new Assessment(this.module, this.title, this.weightPercentage);
        newAssessment.setDescription(this.description);
        newAssessment.setMarkRange(new MarkRange(this.maxMarkRange, this.minMarkRange));
        newAssessment.setMaxMark(this.maxMark);
        for (AssessmentItem assessmentItem : assessmentItems) {
            newAssessment.addAccessmentItem(assessmentItem);
        }
        return newAssessment;
    }
}
